package br.usp.poli.compilador2008.lexical;

import java.lang.reflect.InvocationTargetException;

/**
 * Class used to store a Token Object type, for the lexical analyzer.
 * @author ashimono
 *
 */
public class Token {
	
	//main fields of the Token object
	private String Type;
	private String Arg;
	private String Line;
	private String Column;	
	
	/**
	 * Constructor using the TokenType definitions set in the defined class.		
	 * @param Type
	 * @param Arg
	 * @param Line
	 * @param Column
	 * @throws InvocationTargetException
	 */
	public Token(TokenType Type, String Arg, String Line, String Column) throws InvocationTargetException{
		this(Type.toString(), Arg, Line, Column);
	}
	
	
	/**
	 * Construtor using a String array.
	 * @param array
	 * @throws InvocationTargetException
	 */
	public Token(String[] array) throws InvocationTargetException{
		if (array.length>4){
			 throw new InvocationTargetException(null, "Array is too big");
		}
		this.Type = array[0];
		this.Arg = array[1];
		this.Line = array[2];
		this.Column = array[3];
	}	
	
	/**
	 * Constructor using a String to define the TokenType
	 * DEPRECATED - Use the constructor with TokenType Instead.
	 * @param Type
	 * @param Arg
	 * @param Line
	 * @param Column
	 * @throws InvocationTargetException
	 */
	@Deprecated
	public Token(String Type, String Arg, String Line, String Column) throws InvocationTargetException{
		if (Type==null || Line == null || Column == null){
			 throw new InvocationTargetException(null, "Array is too big");
		}
		this.Type = Type;
		this.Arg = Arg;
		this.Line = Line;
		this.Column = Column;
	}
	
	/**
	 * Returns the Token as a String.
	 */
	public String toString(){
		String token = "< " + this.Type + ", " + this.Arg + ", " + this.Line + ", " + this.Column + " >";
		return token;
	}
	
	// Setters and Getters
	public void setType(String value){
		this.Type = value;
	}
	
	
	public void setArg(String value){
		this.Arg = value;
	}
	
	
	public void setLine(String value){
		this.Line = value;
	}
	
	
	public void setColumn(String value){
		this.Column = value;
	}
	
	
	public String getType(){
		return this.Type;
	}
	
	
	public String getArg(){
		return this.Arg;
	}
	
	
	public String getLine(){
		return this.Line;
	}
	
	
	public String getColumn(){
		return this.Column;
	}
}
